/*
 * Copyright 2013-2019 Xia Jun(3979434@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************************
 *                                                                                     *
 *                        Website : http://www.farsunset.com                           *
 *                                                                                     *
 ***************************************************************************************
 */
package com.workcell.workdata.im.mvc.controller.system;

import com.workcell.workdata.im.annotation.CreateAction;
import com.workcell.workdata.im.annotation.GreenFunction;
import com.workcell.workdata.im.model.request.TextTranslateRequest;
import com.workcell.workdata.im.model.response.ResponseEntity;
import com.workcell.workdata.im.service.TranslateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/translate")
@Api(produces = "application/json", tags = "文字翻译接口" )
@Validated
public class TranslateController {

	@Resource
	private TranslateService translateService;

	@ApiOperation(httpMethod = "GET", value = "翻译文本")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "text", value = "待翻译文本", paramType = "query", dataTypeClass = String.class),
			@ApiImplicitParam(name = "language", value = "目标语言", paramType = "query", dataTypeClass = String.class)
	})
	@GreenFunction
	@GetMapping(value = "/text")
	public ResponseEntity<String> translate(@RequestParam String text,
                                            @RequestParam String language) {
		TextTranslateRequest request = new TextTranslateRequest();
		request.setText(text);
		request.setLanguage(language);
		return ResponseEntity.ok(translateService.translate(request));
	}

	@ApiOperation(httpMethod = "POST", value = "翻译文本")
	@GreenFunction
	@PostMapping(value = "/text")
	@Validated(CreateAction.class)
	public ResponseEntity<String> translate(@Valid @RequestBody TextTranslateRequest request) {
		return ResponseEntity.ok(translateService.translate(request));
	}
}
